import java.util.ArrayList;

public class Mage extends Piece {
	/*
	 * 8   -[x]- - - - - - - - - -    
	 * 7  [x[M]x]- - - - - - - - -    
	 * 6   -[x]- - - - - - - - - -    
	 * 5   - - - - - x - - - - - -    
	 * 4   - - - - - - - - - - - -      SKY (3)
	 * 3   - - - - - - - - - - - -    
	 * 2   - - - - - - - - - -{x}-    
	 * 1   - - - - - - - - - - - -    
	 * 
	 * 8   - - x - - x - - x - - -    
	 * 7   -[x]- x - x - x - - - -    
	 * 6   - - - - x x x - - - - -    
	 * 5   x x x x x M x x x x x x    
	 * 4   - - - - x x x - - - - -      EARTH (2)
	 * 3   - - - x - x - x - - - -    
	 * 2   - - x - - x - - x -{x}-    
	 * 1   - x - - - x - - - x - -    
	 * 
	 * 8   - - - - - - - - - - - -    
	 * 7   -[x]- - - - - - - - - -    
	 * 6   - - - - - - - - - - - -    
	 * 5   - - - - - x - - - - - -    
	 * 4   - - - - - - - - - - - -      UNDER (1)
	 * 3   - - - - - - - - - -{x}-    
	 * 2   - - - - - - - - -{x{M}x}   
	 * 1   - - - - - - - - - -{x}-    
	 * 	   a b c d e f g h i j k l
	 * The Mage moves like a queen. It can also leap from top to bottom and vice versa, but there
	 * must not be a piece blocking its way (on the EarthBoard) for it to do so.
	 */
	
	public Mage(int s) {
		super(s);
	}

	protected ArrayList<Square> getAvailableMoves() {
		moves.clear();
		if(getSquare().getBoard().getLevel() == 2) {
			for(int i = getSquare().getRow() + 1; i <= 8; i++) {
				moves.add(getSquare().getFarSquare(Square.NORTH, i - getSquare().getRow()));
				if(moves.get(moves.size() - 1).isOccupied()) {
					i += 8;
				}
			}
			for(int i = getSquare().getRow() + 1; i <= 8; i++) {
				moves.add(getSquare().getFarSquare(Square.NORTHEAST, i - getSquare().getRow()));
				if(moves.get(moves.size() - 1).isOccupied()) {
					i += 8;
				}
			}
			for(int i = getSquare().getCol() + 1; i <= 12; i++) {
				moves.add(getSquare().getFarSquare(Square.EAST, i - getSquare().getCol()));
				if(moves.get(moves.size() - 1).isOccupied()) {
					i += 12;
				}
			}
			for(int i = getSquare().getRow() - 1; i >= 1; i--) {
				moves.add(getSquare().getFarSquare(Square.SOUTHEAST, getSquare().getRow() - i));
				if(moves.get(moves.size() - 1).isOccupied()) {
					i -= 8;
				}
			}
			for(int i = getSquare().getRow() - 1; i >= 1; i--) {
				moves.add(getSquare().getFarSquare(Square.SOUTH, getSquare().getRow() - i));
				if(moves.get(moves.size() - 1).isOccupied()) {
					i -= 8;
				}
			}
			for(int i = getSquare().getRow() - 1; i >= 1; i--) {
				moves.add(getSquare().getFarSquare(Square.SOUTHWEST, getSquare().getRow() - i));
				if(moves.get(moves.size() - 1).isOccupied()) {
					i -= 8;
				}
			}
			for(int i = getSquare().getCol() - 1; i >= 1; i--) {
				moves.add(getSquare().getFarSquare(Square.WEST, getSquare().getCol() - i));
				if(moves.get(moves.size() - 1).isOccupied()) {
					i -= 12;
				}
			}
			for(int i = getSquare().getRow() + 1; i <= 8; i++) {
				moves.add(getSquare().getFarSquare(Square.NORTHWEST, i - getSquare().getRow()));
				if(moves.get(moves.size() - 1).isOccupied()) {
					i += 8;
				}
			}
			moves.add(getSquare().getFarSquare(Square.UP, 1));
			moves.add(getSquare().getFarSquare(Square.DOWN, 1));
		} else if(getSquare().getBoard().getLevel() == 1 || getSquare().getBoard().getLevel() == 3) {
			for(int i = 0; i < 4; i++) {
				moves.add(getSquare().getFarSquare(Square.NORTH + 90 * i, 1));
			}
			moves.add(getSquare().getFarSquare(2 - getSquare().getBoard().getLevel(), 1));
			if(getSquare().getBoard().getLevel() == 1 && !getSquare().getFarSquare(Square.UP, 1).isOccupied()) {
				moves.add(getSquare().getFarSquare(Square.UP, 2));
			} else if(getSquare().getBoard().getLevel() == 3 && !getSquare().getFarSquare(Square.DOWN, 1).isOccupied()) {
				moves.add(getSquare().getFarSquare(Square.DOWN, 2));
			}
		}
		System.out.println(moves);
		return moves;
	}
	
	protected ArrayList<Square> getAvailableCapts() {
		return getAvailableMoves();
	}
	
	public String toString() {
		if(side == 1) {
			return "M";
		} else if(side == 2) {
			return "m";
		} else {
			return "no side";
		}
	}
}
